set -e
set -o pipefail

if [ -z "${MIN_INTERPEAKS}" ]; then MIN_INTERPEAKS=3; fi
if [ -z "${CL_START_NM}" ]; then CL_START_NM=15.0; fi
if [ -z "${CL_END_NM}" ]; then CL_END_NM=23.0; fi
if [ -z "${MIN_DETACHMENT_FORCE}" ]; then MIN_DETACHMENT_FORCE=200.0; fi
if [ -z "${DETACHMENT_STRICTLY_LARGEST}" ]; then DETACHMENT_STRICTLY_LARGEST="True"; fi

if [ -z "${MIN_PEAKS_INCLUDING_DETACHMENT}" ]; then MIN_PEAKS_INCLUDING_DETACHMENT=0; fi
if [ -z "${MAX_PEAKS_INCLUDING_DETACHMENT}" ]; then MAX_PEAKS_INCLUDING_DETACHMENT=18; fi
if [ -z "${MIN_DETACHMENT_Z_NM}" ]; then MIN_DETACHMENT_Z_NM=0; fi
if [ -z "${MAX_DETACHMENT_Z_NM}" ]; then MAX_DETACHMENT_Z_NM=9999; fi
if [ -z "${MIN_DETACHMENT_D_NM}" ]; then MIN_DETACHMENT_D_NM=0; fi
if [ -z "${MAX_DETACHMENT_D_NM}" ]; then MAX_DETACHMENT_D_NM=9999; fi

if [ -z "${MAX_INTERPEAKS}" ]; then MAX_INTERPEAKS=24; fi
if [ -z "${MIN_DETACHMENT_CL_NM}" ]; then MIN_DETACHMENT_CL_NM=150.0; fi
if [ -z "${MAX_DETACHMENT_CL_NM}" ]; then MAX_DETACHMENT_CL_NM=500.0; fi
if [ -z "${MAX_INNER_PEAK_FORCE_PN}" ]; then MAX_INNER_PEAK_FORCE_PN=450.0; fi

fixedDeflectionSensitivityNmPerV=$DEFL_SENS; fixedSpringConstantNPerM=$K; kineticsSuffix=${KINETICS_SUFFIX//*/_${KINETICS_SUFFIX}}; for d in $DIRS; do p=$(dirname ${d}); b=$(basename ${d})${fixedDeflectionSensitivityNmPerV//*/_${fixedDeflectionSensitivityNmPerV}}${fixedSpringConstantNPerM//*/_${fixedSpringConstantNPerM}}; cd ~/work/rcs/refolding-read-only/core/src/main/python && python anywhere_filter.py --processed_playlist=${p}/analysis/${b}_analysis/${b}.hkp --cl_start_nm=${CL_START_NM} --cl_end_nm=${CL_END_NM} --min_such_peaks=${MIN_INTERPEAKS} --max_such_peaks=${MAX_INTERPEAKS} --max_peaks_including_detachment=${MAX_PEAKS_INCLUDING_DETACHMENT} --min_detachment_cl_nm=${MIN_DETACHMENT_CL_NM} --max_detachment_cl_nm=${MAX_DETACHMENT_CL_NM} --max_inner_peak_force_pn=${MAX_INNER_PEAK_FORCE_PN} --detachment_strictly_largest=${DETACHMENT_STRICTLY_LARGEST} && echo "To continue, set:" && echo "INPUT_PATH_FILENAME=selected_${CL_START_NM}_${CL_END_NM}_${MIN_INTERPEAKS}_${MAX_INTERPEAKS}_${MIN_PEAKS_INCLUDING_DETACHMENT}_${MAX_PEAKS_INCLUDING_DETACHMENT}_${MIN_DETACHMENT_CL_NM}_${MAX_DETACHMENT_CL_NM}_${MIN_DETACHMENT_Z_NM}_${MAX_DETACHMENT_Z_NM}_${MIN_DETACHMENT_D_NM}_${MAX_DETACHMENT_D_NM}_${MAX_INNER_PEAK_FORCE_PN}_${DETACHMENT_STRICTLY_LARGEST}.hkp"; done
